﻿namespace SMAPlugin.Common
{
	internal class StrategyControlVM : Plugins.Base.Common.StrategyControlVMBase
	{
		#region Properties

		public new StrategyControlData Data
		{
			get
			{
				return (StrategyControlData)base.Data;
			}
		}

		public int SlowSMAPeriod
		{
			get
			{
				return this.Data.SlowSMAPeriod;
			}
			set
			{
				this.Data.SlowSMAPeriod = value;
			}
		}

		public int FastSMAPeriod
		{
			get
			{
				return this.Data.FastSMAPeriod;
			}
			set
			{
				this.Data.FastSMAPeriod = value;
			}
		}

		public int Volume
		{
			get
			{
				return this.Data.Volume;
			}
			set
			{
				this.Data.Volume = value;
			}
		}

		public WorkingMode WorkingMode
		{
			get
			{
				return this.Data.WorkingMode;
			}
			set
			{
				this.Data.WorkingMode = value;
			}
		}

		public decimal FixedWin
		{
			get
			{
				return this.Data.FixedWin;
			}
			set
			{
				this.Data.FixedWin = value;
			}
		}

		#endregion

		#region Public Methods

		public StrategyControlVM() : base(new StrategyControlData())
		{
		}

		protected override string ValidateField(string fieldName)
		{
			string result = null;

			if (fieldName == "SlowSMAPeriod")
			{
				if (this.SlowSMAPeriod < this.FastSMAPeriod)
				{
					base.ValidatedErrors[fieldName] = true;
					result = "The slow SMA has to be bigger than the fast";
				}
				else if (this.SlowSMAPeriod == 0)
				{
					base.ValidatedErrors[fieldName] = true;
					result = "The slow SMA has to be bigger than 0";
				}
			}
			else if (fieldName == "FastSMAPeriod")
			{
				if (this.FastSMAPeriod > this.SlowSMAPeriod)
				{
					base.ValidatedErrors[fieldName] = true;
					result = "The fast SMA has to be smaller than the slow";
				}
				else if (this.FastSMAPeriod == 0)
				{
					base.ValidatedErrors[fieldName] = true;
					result = "The fast SMA has to be bigger than 0";
				}
			}
			else if (fieldName == "Volume")
			{
				if (this.Volume <= 0)
				{
					base.ValidatedErrors[fieldName] = true;
					result = "The volume has to be greater than 0";
				}
			}
			else if (fieldName == "WorkingMode")
			{
				if (this.WorkingMode == WorkingMode.None)
				{
					base.ValidatedErrors[fieldName] = true;
					result = "You must select a working mode";
				}
				else if (this.WorkingMode == WorkingMode.FastSlowCrossFixedWin && this.FixedWin <= 0)
				{
					base.ValidatedErrors[fieldName] = true;
					result = "You must enter a fixed win greater than 0";					
				}
			}
			else if (fieldName == "FixedWin")
			{
				if (this.WorkingMode == WorkingMode.FastSlowCrossFixedWin && this.FixedWin <= 0)
				{
					base.ValidatedErrors[fieldName] = true;
					result = "You must enter a fixed win greater than 0";
				}
			}

			return result;
		}

		#endregion
	}
}
